package com.demo.server.init;

import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;

import com.demo.server.interceptor.MybatisInterceptor;

import lombok.extern.slf4j.Slf4j;

@ConditionalOnProperty(value = "custom.sqlLimit.enable")
@Slf4j
@Component
public class MybatisInit implements ApplicationRunner{
	
	@Autowired
	SqlSessionFactory sqlSessionFactory;
	
	@Override
	public void run(ApplicationArguments args) throws Exception {
		// TODO Auto-generated method stub
		log.info("Mybatis 初始化, 保证MybatisInterceptor 优先执行>>>>");
		sqlSessionFactory.getConfiguration().addInterceptor(new MybatisInterceptor());
	}

}
